const MAP={
	'/category/create':'create()',
	'/category/delete':'remove()',
	'/category/list':'list()',
	'/category/detail':'detail()',	
	'/category/swap':'swap()',
	'/category/product/list':'productList()',	
	}
class JQCategoryController extends global.JQBaseController {
     constructor(url,conn,req_obj) {
		super(url,conn,req_obj);
	
       // super.name = name;
    }
	
//生成订单
	async create(){
		const service = global.JQService.instance(
			'category_service/create',this.conn,this.req_obj,this.params);
		let data =service.do_action();
		return data;
	}
	
	async remove(){
		const service = global.JQService.instance(
			'category_service/delete',this.conn,this.req_obj,this.params);
		let data =service.do_action();
		return data;
	}
	
	
	async swap(){
		const service = global.JQService.instance(
			'category_service/swap',this.conn,this.req_obj,this.params);
		let data =service.do_action();
		return data;
	}
	
	async detail(){
		const service = global.JQService.instance(
			'product_service/detail',this.conn,this.req_obj,this.params);
		let data =service.do_action();
		return data;
	}
	
	
	async list(){
		console.log('list::1111')
		let data_obj = this.req_obj.data_obj;
		if(!data_obj)data_obj={};
		let page = data_obj.page;
		console.log('list::2222')
		let page_size = data_obj.size;
		if(!page_size ||page_size<0)page_size=2000;
		if(!page ||page<0)page=1;
		page--;
		page=page*2000;
		console.log('list::33333')
		
		if(!data_obj.first || data_obj.first<=0)data_obj.first =page;
		data_obj.size=page_size;
		console.log('list::4444')
		this.req_obj.data_obj= data_obj;
		const service = global.JQService.instance(
			'category_service/list',this.conn,this.req_obj,this.params);
		let data =service.do_action();
		return data;
	}
	
	
	async productList(){
	console.log('list::1111')
	let data_obj = this.req_obj.data_obj;
	if(!data_obj)data_obj={};
	let page = data_obj.page;
	console.log('list::2222')
	let page_size = data_obj.size;
	if(!page_size ||page_size<0)page_size=2000;
	if(!page ||page<0)page=1;
	page--;
	page=page*2000;
	console.log('list::33333')
	
	if(!data_obj.first || data_obj.first<=0)data_obj.first =page;
	data_obj.size=page_size;
	console.log('list::4444')
	this.req_obj.data_obj= data_obj;
	const service = global.JQService.instance(
		'category_service/product_list',this.conn,this.req_obj,this.params);
	let data =service.do_action();
	return data;
	}
	
	
    async  dispatch() {
		super.dispatch();
		
		let req = this.req_obj;
		let func = MAP[this.url];
		
		if(func){
			console.log('dispatch'+ '  ' +  func);
			func = 'this.'+func;
			console.log('dispatch'+ '  ' +  func);
			let res_data = await eval(func);
			return res_data;
		}else return null;
		
		
    }
	
	
}
module.exports = JQCategoryController;